import { defineStore } from "pinia";
import { showDatabases } from '@/api/index'
// Create the connectInfo store module
export const connectInfoStore = defineStore("connectInfo", {
  state() {
    return {
      info: {
				name: "",
        host: "",
        port: "",
        username: "",
        password: "",
      },
      connected: false,
			databaseInfo: []
    };
  },
  actions: {
    // Define your actions here
    // For example:
    setConnectInfo(payload) {
      this.info = payload;
    },
    setConnected(connected) {
       this.connected = connected;
    },
		updateDatabaseInfo(callback){
			showDatabases(this.info).then(res=>{
				if(res.code == 200){
					this.databaseInfo = res.data;
					if(callback){
						callback();
					}
				}
			}).catch(error=>{
				console.error(error);
			})
		}
  },
  /**
   * getters是用来获取state中的数据的，类似于vue中的computed
   */
  getters: {
    // Define your getters here
    // For example:
    // infoQ() {
    //     console.log(this.info + "!!!!!");
    //   return this.info;
    // },
  },
});

// Export the store instance
// export default connectInfoStore;
